var itmes = document.getElementsByClassName('itme');//获取图片
var points = document.getElementsByClassName('point');//获取点
var goPreBtn = document.getElementById('goPre');
var goNextBtn = document.getElementById('goNext');
var index = 0;//index表示第几张照片在展示，也就是说第index照片有active这个属性;还可以表示第几个点在展示
var time = 0;//定时器图片跳转参数
var clearActive = function(){
	for(var i = 0;i < itmes.length;i++){
		itmes[i].className = 'itme';
	}
	for(var i = 0;i < points.length;i++){
		points[i].className = 'point';
	}
}
//把上张图片的className = 'itme active' 变为  className = 'itme'，也就是清除active

//goIndex给classname添加active类名
var goIndex = function(){
	clearActive();
	points[index].className = 'point active';
	itmes[index].className = 'itme active';
}

//下一张的功能
var goNext = function(){
	if(index < 4){
		index++;
	}
	else{
		index = 0;
	}
	goIndex();
	time = 0;
}

//上一张的功能
var goPre = function(){
	if(index == 0){
		index = 4;
	}
	else{
		index--;
	}
	goIndex();
	time = 0;
}
goNextBtn.addEventListener('click',function(){
	goNext();
})
goPreBtn.addEventListener('click',function(){
	goPre();
})

for(var i = 0;i<points.length;i++){
	points[i].addEventListener('click',function(){
		var pointsIndex = this.getAttribute('data-index');
		index = pointsIndex;
		goIndex();
		time = 0;
	})
}

//2000ms,跳转一次

setInterval(function(){
	time++;
	if(time == 20){
		goNext();
		time = 0;
	}
},100)//100ms执行一次函数